Open
Conversation
Contributor
|
Not sure if I see the need for this change. You always have to pass in a patch which corresponds to the base. If it's an incorrect patch you can then get garbage data even if func (options *Options) ApplyPatchRecovery(root interface{}, patch Patch) (res interface{}, err error) {
defer func() {
if r := recover(); r != nil {
err = fmt.Errorf("panic recovered: %v", r)
}
}()
res = options.ApplyPatch(root, patch)
} |
Member
Author
|
That seems less clean to me considering (1) panics are slow in Go compared to normal errors, as they need to unwind the stack, and (2) panics are not specific to mismatches. This is intended to handle the specific error we are seeing in production. Panics can still happen for other reasons than mismatch (i.e. actual code bugs). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This changes the API to return errors instead of panicking. Adds
MustApplyPatch()that preserves the panic behaviour.This is so we can simply catch the error rather than log it to Sentry as a panic.
I've also updated
go.modto 1.25 and run gopls's modernize tool to updateinterface{}->anyetc.